package com.ebupt.migu.music.common.util;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class TimeRangeChecker {

    // 判断给定的时间是否在指定的时间段内
    public static boolean isTimeInRange(String timeToCheckStr, String startTimeStr, String endTimeStr) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime timeToCheck = LocalDateTime.parse(timeToCheckStr, formatter);
        LocalDateTime startTime = LocalDateTime.parse(startTimeStr, formatter);
        LocalDateTime endTime = LocalDateTime.parse(endTimeStr, formatter);

        return !timeToCheck.isBefore(startTime) && !timeToCheck.isAfter(endTime);
    }

    public static void main(String[] args) {
        // 示例：检查当前时间是否在指定时间段内
        String currentTime = "2023-04-01 15:00:00";
        String startTime = "2023-04-01 08:00:00";
        String endTime = "2023-04-01 18:00:00";
        boolean isInRange = isTimeInRange(currentTime, startTime, endTime);
        System.out.println("当前时间是否在指定时间段内: " + isInRange);
    }
}